#!/usr/bin/env python
"""
Nagios plugin that monitors the Grid Manager service on a NorduGrid ARC CE, aka
NorduGrid front-end.

"""
__author__ = "Placi Flury grid@switch.ch"
__copyright__ = "Copyright 2010, SMSCG an AAA/SWITCH project"
__date__ = "12.11.2008"
__version__ = "0.2.0"
__last_change = '30.11.2011'

# last change: A-Rex check

import sys
from nagios_plugin import NagiosPluginBasic,LocalService


class GridManager(NagiosPluginBasic):
    """
    Checks whether Gridmanager service is running. It's a local check
    without any connectivity testing.
    """
    def __init__(self):
        parser = NagiosPluginBasic.getOptions(self)
        parser.remove_option("-c")   # removing thresholds
        parser.remove_option("-w")
        parser.remove_option("-H")   # remove hostname option
        parser.parse_args()


    def main(self):

        service_new = LocalService("arched-arex")
        service_old = LocalService("grid-manager")
        
	if service_new.getpid() >= 0:
            service = service_new
        else:
            service = service_old
        msg, return_code = service.getstate()

        print msg
        sys.exit(return_code)


if __name__ == "__main__":
    g = GridManager()
    g.main()
